import subprocess
import os
from concurrent.futures import ThreadPoolExecutor

def run_ai_model(image_path):
    command = ['python', 'ai_model.py', image_path]
    result = subprocess.run(command, capture_output=True, text=True)
    if result.returncode == 0:
        print(f'命令执行成功: {image_path}')
        print(result.stdout)
    else:
        print(f'命令执行失败: {image_path}')
        print(result.stderr)

def process_image(image_path):
    print(f'运行模型处理：{image_path}')
    run_ai_model(image_path)

def process_directory(directory):
    image_paths = []
    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif', '.tiff')):
                image_path = os.path.join(root, file)
                image_paths.append(image_path)

    with ThreadPoolExecutor() as executor:
        executor.map(process_image, image_paths)

def main(directories):
    for directory in directories:
        print(f'处理文件夹: {directory}')
        process_directory(directory)


# 指定多个文件夹路径
folders = ['./data/208', './data/209', './data/363', './data/364']
main(folders)
